<script>

$('input[name="yunfeiid"]').first().click();

var yunfei = <?php echo $this->yunfeiJs;?>;

var total = <?php echo $this->totalPrice;?>;

var totalPriceAll = 0.00;

<?php if ($this->hasLog && $this->validatePrize == 0):?>

var discount = <?php echo MEMBER_DOLLAR;?>;

<?php else:?>

var discount = 0.00;

<?php endif;?>

var ce_rate = <?php echo CE_SSFKH - 1;?>;

var cen_rate = <?php echo CE_SSFKHNOPASS - 1;?>;

var paypal_rate = <?php echo PAYPAL_RATE - 1 ;?>;

var yunfei_all = 0.00;

<?php if ($this->disSave): ?>
var dis_save = <?php echo $this->disSave;?>;
<?php else:?>
var dis_save = 0;
<?php endif;?>

$(function(){

	$('#paypal_email').hide();

	load_pay($('input[name="yunfeiid"]').first().val());

});



function changeyunfei(obj)

{

	if ($(obj)[0].checked == true) {		

		load_pay($(obj).val());

	}

}



function load_pay(id)

{
	$('input[name="yunfeiids"]').val(id);

	if (yunfei.length > 0) {

		for (i=0;i<yunfei.length;i++) {				

			if (yunfei[i].pid == id) {

				totalPriceAll = total + parseFloat(yunfei[i].price); 

				yunfei_all = yunfei[i].price;

			}

		}

		if (totalPriceAll == 0) {

			GGSHOP.msgBox.show('ERROR', 'ERROR');

			return;

		}

	} else {

		if (id == 0) {

			totalPriceAll = total;

		} else {

			GGSHOP.msgBox.show('ERROR', 'ERRORs');

			return;

		}

	}	

//	$('input[name="usecoupon"]').val($('input[name="coupon"]').val());

//	

//	if (($('input[name="usecoupon"]').val() - $('input[name="usercoupon"]').val()) > 0 || ($('input[name="usecoupon"]').val() - totalPriceAll) > 0) {

//		GGSHOP.msgBox.show('ERROR', 'You input coupon too more!');		

//		return false;

//	}	

//	if ($('input[name="usecoupon"]').val() > 0) {

//		totalPriceAll = totalPriceAll - $('input[name="usecoupon"]').val();

//	}	

	totalPriceAll = totalPriceAll - $('input[name="usecoupon1"]').val();

	totalPriceAll = totalPriceAll - discount;

	<?php if (defined('SELL_VALIDATE')):?>
		totalPriceAll = totalPriceAll * <?php echo (1-SELL_OFF);?>
	<?php endif;?>

	$('#ce_pay_rate').html('Charging fee: $' + formatfloat(ce_rate * totalPriceAll, 2));

	$('#cen_pay_rate').html('Charging fee: $' + formatfloat(cen_rate * totalPriceAll, 2));

	$('#paypal_pay_rate').html('Charging fee: $' + formatfloat(paypal_rate * totalPriceAll, 2));	

	$('input[name="paymentMethod"]').each(function(){

		if ($(this)[0].checked == true) {

			$(this)[0].click();

		}

	});

	return true;

}



function confirmCancel(){



	if(confirm("Sure to cancel this order?")){



		return true;



	}else{



		return false;



	}



}



function changeCoupon()

{

	id = 0;

	$('input[name="yunfeiid"]').each(function(){

		if ($(this)[0].checked == true) {

			id = $(this).val();

		}

	});

	load_pay(id);

}

function dopay(){



	var hasSelect=false;

	var pay = '';

	$('input[name="usecoupon"]').val($('input[name="usecoupon1"]').val());

	$('input[name="usecouponcode"]').val($('input[name="usecouponcode1"]').val());

	if (!load_pay($('input[name="yunfeiids"]').val())) {

		return;

	}

	$('input[name="paymentMethod"]').each(



		function(){

			if($(this)[0].checked==true){

				pay = $(this).val();

				hasSelect=true;

			}



		}



	);



	if(!hasSelect){



		GGSHOP.msgBox.show('ERROR', 'Please select a payment method!');



		$('#paymentForm').submit(



			function(){



				return false;



			}



		);



	}else{

		if (pay == 'paypal' && ($('#paypal_email_text').val() == '' || $('#paypal_email_text').val() == 'YourMail@email.com')) {

			

			GGSHOP.msgBox.show('ERROR', 'Please input your email!');

			$('#paymentForm').submit(

					function(){

						return false;

					}

			);

			return;

		}

		$('#paymentForm')[0].submit();



		GGSHOP.loading.show();



	}



}







var payment={



	changeToPaypal:function(){

		$('#order-total-div').show();		

		$('input[name="payment_action"]').val('pay-paypal');

		$('#paypal_email').show();

		$('#ship_all').html(yunfei_all);

		fee = $('#paypal_pay_rate').html().substr(15,$('#paypal_pay_rate').html().length);

		$('#fee_all').html(fee);		

		save = formatfloat($('input[name="usecoupon1"]').val(),2)+ discount;			
		$('#save_all').html(formatfloat(save+dis_save, 2));

		totalAll = formatfloat(total,2)+formatfloat(yunfei_all,2)+formatfloat(fee,2);
		totalAll = formatfloat(totalAll,2)
		$('#total_all').html(formatfloat(totalAll+dis_save, 2));

		$('#should_pay').html(totalAll-save);
		$('#credit_div').hide();

	},

	 changeTocredit:function(){

		$('#order-total-div').show();

		$('input[name="payment_action"]').val('pay-credit');

		$('#paypal_email').hide();

		$('#ship_all').html(yunfei_all);

		fee = 0;

		$('#fee_all').html(fee);		

		save = discount;			
		<?php if (defined('SELL_VALIDATE')):?>
			save = formatfloat(save + formatfloat((total - save)  * <?php echo SELL_OFF;?>,2),2);
		<?php endif;?>
		$('#save_all').html(formatfloat(save+dis_save, 2));
		
		totalAll = formatfloat(total,2)+formatfloat(yunfei_all,2)+formatfloat(fee,2);
		totalAll = formatfloat(totalAll,2);
		
		$('#total_all').html(formatfloat(totalAll+dis_save, 2));
		
		$('#should_pay').html(formatfloat(totalAll-save,2));
		$('#credit_div').show();
		$('#should_pay_credit').html(formatfloat((totalAll-save)/5,2));
		
	},
	
    changeTossfkh:function(){

		$('#order-total-div').show();

		$('input[name="payment_action"]').val('pay-ssfkh');

		$('#paypal_email').hide();

		$('#ship_all').html(yunfei_all);

		fee = $('#ce_pay_rate').html().substr(15,$('#ce_pay_rate').html().length);

		$('#fee_all').html(fee);		

		save = formatfloat($('input[name="usecoupon1"]').val(),2)+ discount;			
		<?php if (defined('SELL_VALIDATE')):?>
			save = formatfloat(save + formatfloat((total - save)  * <?php echo SELL_OFF;?>,2),2);
		<?php endif;?>
		$('#save_all').html(formatfloat(save+dis_save, 2));
		
		totalAll = formatfloat(total,2)+formatfloat(yunfei_all,2)+formatfloat(fee,2);
		totalAll = formatfloat(totalAll,2);
		
		$('#total_all').html(formatfloat(totalAll+dis_save, 2));
		
		$('#should_pay').html(formatfloat(totalAll-save,2));
		$('#credit_div').hide();
		
	},

	changeTossfkh1:function(){

		$('#order-total-div').show();

		$('input[name="payment_action"]').val('pay-ssfkh1');

		$('#paypal_email').hide();

		$('#ship_all').html(yunfei_all);

		fee = $('#ce_pay_rate2').html().substr(15,$('#paypal_pay_rate').html().length);

		$('#fee_all').html(fee);		

		save = formatfloat($('input[name="usecoupon1"]').val(),2)+ discount;			
		<?php if (defined('SELL_VALIDATE')):?>
			save = formatfloat(save + formatfloat((total - save)  * <?php echo SELL_OFF;?>,2),2);
		<?php endif;?>
		$('#save_all').html(formatfloat(save+dis_save, 2));
		
		totalAll = formatfloat(total,2)+formatfloat(yunfei_all,2)+formatfloat(fee,2);
		totalAll = formatfloat(totalAll,2);
		
		$('#total_all').html(formatfloat(totalAll+dis_save, 2));
		
		$('#should_pay').html(formatfloat(totalAll-save,2));
		$('#credit_div').hide();
		
	},

	changeToyourpay:function(){

		$('#order-total-div').show();

		$('input[name="payment_action"]').val('pay-yourspay');

		$('#paypal_email').hide();

		$('#ship_all').html(yunfei_all);

		fee = $('#ce_pay_rate4').html().substr(15,$('#paypal_pay_rate').html().length);

		$('#fee_all').html(fee);		

		save = formatfloat($('input[name="usecoupon1"]').val(),2)+ discount;			
		<?php if (defined('SELL_VALIDATE')):?>
			save = formatfloat(save + formatfloat((total - save)  * <?php echo SELL_OFF;?>,2),2);
		<?php endif;?>
		$('#save_all').html(formatfloat(save+dis_save, 2));
		
		totalAll = formatfloat(total,2)+formatfloat(yunfei_all,2)+formatfloat(fee,2);
		totalAll = formatfloat(totalAll,2);
		
		$('#total_all').html(formatfloat(totalAll+dis_save, 2));
		
		$('#should_pay').html(formatfloat(totalAll-save,2));
		
	},

    changeTossfkhnopass:function(){

		$('#order-total-div').show();

		$('input[name="payment_action"]').val('pay-nopassssfkh');

		$('#paypal_email').hide();

		$('#ship_all').html(yunfei_all);

		fee = $('#cen_pay_rate').html().substr(15,$('#paypal_pay_rate').html().length);

		$('#fee_all').html(fee);		

		save = formatfloat($('input[name="usecoupon1"]').val(),2) + discount;			
	
		$('#save_all').html(formatfloat(save+dis_save, 2));

		totalAll = formatfloat(total,2)+formatfloat(yunfei_all,2)+formatfloat(fee,2);

		$('#total_all').html(formatfloat(totalAll+dis_save, 2));

		$('#should_pay').html(totalAll-save);

	},



	changeToWest:function(){


		$('#westu').parent().next().show();
		$('input[name="payment_action"]').val('pay-west');
		$('#order-total-div').show();
		

		$('#paypal_email').hide();

		$('#ship_all').html(yunfei_all);

		fee = $('#ce_pay_rate').html().substr(15,$('#ce_pay_rate').html().length);

		$('#fee_all').html(fee);		

		save = formatfloat($('input[name="usecoupon1"]').val(),2) + discount;		
		<?php if (defined('SELL_VALIDATE')):?>
		save = formatfloat(save + formatfloat((total - save)  * <?php echo SELL_OFF;?>,2),2);
		<?php endif;?>	
	
		$('#save_all').html(formatfloat(save+dis_save, 2));

		totalAll = formatfloat(total,2)+formatfloat(yunfei_all,2)+formatfloat(fee,2);

		$('#total_all').html(formatfloat(totalAll+dis_save, 2));

		$('#should_pay').html(formatfloat(totalAll-save,2));
		$('#credit_div').hide();

	},



	changeToTT:function(){



		$('#paymentForm').attr('action','pay-tt');



	}



}

GGSHOP.loading.show();
GGSHOP.address.setCurrent(<?php echo $this->addressId;?>);

</script>
			<?php if ($this->shouldPay):?>
    		<h2 class="titlebar clearfix">YOUR SHIPPING OPTIONS</h2>

    		<div class="order-ship-opt">

				<h3>Congratulation! You qualify for free standard shipping!</h3>

                <div>Delivery times are calculated in business days for orders placed before 1PM Pacific Standard Time.</div>

                <div class="o-opts">

                	<?php if ($this->yunfeiArray):?>

                		<?php $i = 0;?>

                		<?php foreach($this->yunfeiArray as $value):?>

                			<?php $i++;?>

                			<?php if ($value['openflag']):?>

                			<div><input type="radio" name="yunfeiid" value="<?php echo $value['pid']?>" id="shipOptItem<?php echo $i;?>" onclick="changeyunfei(this);"/><label for="shipOptItem<?php echo $i;?>"><?php echo $value['carrier'];?> <?php echo $value['transittime'];?> Business Day Shipping - 

                			<?php if ($value['price']==0.00):?>

			        			<span>Free!</span>

							 <?php else:?>

							    $<?=$value['price']?>

							  <?php endif;?>

							 </label></div>

                			<?php endif;?>

                    	<?php endforeach;?>

                    <?php else:?>

                    		<div><input type="radio" name="yunfeiid" id="shipOptItem1" value="0" onclick="changeyunfei(this);"/><label for="shipOptItem1">Standard Shipping - <span>FREE!</span> </label></div>

                    <?php endif;?>   

                    <input type="hidden" name="contactid" id="contactid" value="<?php echo $this->contactid;?>"></input>                 

                </div>                

    		</div>
    		<?php endif;?>
			<?php if ($this->shouldPay):?>
            <div id="pay_info">

	            <form id="paymentForm" action="product-doship" method="post">  		

	            <h2 class="titlebar">YOUR PAYMENT INFORMATION</h2>

	            <h3 class="payment-tlt">Please select method of payment:</h3>

	            <div class="order-payment">
					
	            	<div class="mitem method-item" style="display:none;"><input name="paymentMethod" type="radio" value="paypal" id="payMentMethod2" /><label for="payMentMethod2">&nbsp;Paypal&nbsp;&nbsp;<span class="lred" id="paypal_pay_rate">Charging fee: $<?=$this->total*(PAYPAL_RATE-1)?></span></label><span class="paypal-logo"><img src="images/paypal.gif" /></span></div>

	            	<div class="mitem paypal-info" style="display:none;">

	                    <strong>Please fill up your paypal email, We will send you the Request In 12 Hours for The PayPal payment, Please pay attention for your Paypal email! </strong>

	               		<div class="paypal-email" id="paypal_email" style="display: none">Paypal Account: <input type="text" value="YourMail@email.com" name="paypal_email" id="paypal_email_text" onfocus="this.value=''"/></div>

	                	<br/>

	                	<input type="hidden" name="yunfeiids" value=""></input>

	                	<input type="hidden" name="usecoupon" value=""></input>

	                	<input type="hidden" name="usecouponcode" value=""></input>

	                	<input type="hidden" name="usercoupon" value="<?php echo $this->userDollar;?>"></input>

	                	<input type="hidden" name="contactid" value="<?php echo $this->contactid;?>"></input>

	                	<input type="hidden" name="payment_action" value=""></input>

	                </div>
	                
	                <div class="mitem method-item" style="display:none;"><input name="paymentMethod" type="radio" value="ssfkh1" id="payMentMethod4" /><label for="payMentMethod4">&nbsp;<strong>Credit Card Channel 1 (VISA)</strong>&nbsp;&nbsp;<span class="lred" id="ce_pay_rate4" style="display:none;">Charging fee: $<?=$this->total*(CE_SSFKH-1)?></span></label><span class="credit-card-logo"><img src="images/creditCard1.jpg" /></span></div>
	                <div class="mitem method-item" ><input name="paymentMethod" type="radio" value="ssfkh1" id="payMentMethod3" /><label for="payMentMethod3">&nbsp;<strong>Credit Card Channel 1 (VISA)</strong>&nbsp;&nbsp;<span class="lred" id="ce_pay_rate2" style="display:none;">Charging fee: $<?=$this->total*(CE_SSFKH-1)?></span></label><span class="credit-card-logo"><img src="images/creditCard1.jpg" /></span></div>
	                <div id="paycardinfo"></div>
			<?php if ($this->canUseCredit):?>
	                <div class="mitem method-item" >
	                <input name="paymentMethod" type="radio" value="credit" id="payMentMethod5" />
	                <label for="payMentMethod5"><strong>Credits Payment (Your Available Credits: $<?php echo $this->creditAmount;?>)</strong>&nbsp;&nbsp;
	                <a href="http://www.fancycheapjersey.com/bring-a-friend-and-earn-with-us" target="_blank">How to Earn Credits?</a></label></div>
	                <?php else:?>
	                <div class="mitem method-item" style="color:#ccc;"><input name="paymentMethod" type="radio" value="credit" id="payMentMethod5" disabled="disabled" /><label for="payMentMethod5">&nbsp;<strong>Credits Payment (Your Available Credits: $<?php echo $this->creditAmount;?>. Not enough credits.)</strong>&nbsp;&nbsp;<a href="http://www.fancycheapjersey.com/bring-a-friend-and-earn-with-us" target="_blank">How to Earn Credits?</a></label></div>
	                <?php endif;?>
	                <div class="mitem method-item" style="display:none;"><input name="paymentMethod" type="radio" value="ssfkh" id="payMentMethod1" /><label for="payMentMethod1">&nbsp;<strong>Credit Card Channel 2 (VISA)</strong>&nbsp;&nbsp;<span class="lred" id="ce_pay_rate" style="display:none;">Charging fee: $<?=$this->total*(CE_SSFKH-1)?></span></label><span class="credit-card-logo"><img src="images/creditCard1.jpg" /></span></div>
                    
                    <div class="mitem method-item"><input onclick="payment.changeToWest();$('#paycardinfo').html('');" name="paymentMethod" type="radio" value="westu" id="westu" />&nbsp;<label for="westu"><strong>Western Union Payment</strong> <span class="credit-card-logo"><img src="images/westernunion.jpg" /></span></label></div>

	                <div class="mitem method-info" style="display:none;">
                    		<div>Western union payment information:</div>
							<div>Name：First name:LiQian  Last name:Zou<br/><span style="color:red">Just get money from this Western Union receiver name!</span></div>
							<div>National：China</div>
							<br />
							<div>Bank transfer information:</div>
							<div>Account number:  662658006656</div>
							<div>Benficiary name: Liangcheng Li</div>
							<div>Bank name: Bank of China Guangdong Branch Cha Jiao Sub-Branch</div>
							<div>Bank Address: 7-9, Yuecheng Road, GuangZhou China</div>
							<div>Bank Swift Code: BKCHCNBJ400</div>
                    </div>
                    
	            </div>
	            <h3 class="payment-tlt" style="margin-top:20px;">Leave Your Facebook or Twitter account(You will receive your jerseys' pictures on facebook before they are delivered.)</h3>
	            <div class="order-payment">	            	
	            	<div class="mitem method-item"><input id="facebookInput" name="sns" type="radio" value="facebook" <?php if ($this->facebook) {echo 'checked';}?>/><label for="facebookInput">&nbsp;Your Facebook:&nbsp;&nbsp;<span class="paypal-logos"><input onclick="$(this).parent().parent().prev()[0].checked=true;" type="text" name="facebook" value="<?php echo $this->facebook;?>"/></span></label></div>
	            	<div class="mitem method-item"><input id="twitterInput" name="sns" type="radio" value="twitter" <?php if ($this->twitter) {echo 'checked';}?>/><label for="twitterInput">&nbsp;Your Twitter:&nbsp;&nbsp;<span class="paypal-logos"><input onclick="$(this).parent().parent().prev()[0].checked=true;" type="text" name="twitter" value="<?php echo $this->twitter;?>"/></span></label></div>
	            </div>

	            <div class="order-totalDiv" id="order-total-div">

	            	<div class="span_left">Shipping Fee</div>

	            	<div class="span_right ship_all">$<span id="ship_all">0</span></div>

	            	

	            	<div class="span_left bg">Payment Surcharge</div>

	            	<div class="span_right fee_all bg">$<span id="fee_all">0</span></div>

	            	

	            	<div class="span_left">Total</div>

	            	<div class="span_right total_all">$<span id="total_all">0</span></div>

	            	

	            	<div class="span_left bg">Saved</div>

	            	<div class="span_right save_all bg">-$<span id="save_all">0</span></div>

	            	

	            	<div class="span_left">Total Amount</div>

	            	<div class="span_right should_pay">$<span id="should_pay">0</span></div>	
	            	<div id="credit_div" style="display:none">
	            	<div class="span_left bg">Total Credits</div>
	            	<div class="span_right should_pay bg"><span id="should_pay_credit">0</span> Credits</div>	            	
	            	</div>
                </div>

	            <div class="submit-my-order"><input id="payMyOrderBtn" class="addr-btn1 spbg" type="button" value="Loading..."/></div>

	        	</form>				

            </div>   
            <?php else:?>
            	<div id="pay_info">
				<input type="hidden" name="yunfeiid" id="shipOptItem1" value="0" onclick="changeyunfei(this);"/>
	            <form action="product-doshipfree" method="post">  		
						<input type="hidden" name="yunfeiids" value="0"></input>

	                	<input type="hidden" name="usecoupon" value=""></input>

	                	<input type="hidden" name="usecouponcode" value=""></input>

	                	<input type="hidden" name="usercoupon" value="<?php echo $this->userDollar;?>"></input>

	                	<input type="hidden" name="contactid" value="<?php echo $this->contactid;?>"></input>

	                	<input type="hidden" name="payment_action" value=""></input>
	            
				<div class="submit-my-order"><input id="payMyOrderBtn" class="addr-btn1 spbg" type="button" value="Pay My Order"/></div>

	        	</form>				

            </div>   
            <?php endif;?>
			<script>
				$('#payMentMethod2').click(function(){
					payment.changeToPaypal();
				});
				$('#payMentMethod1').click(function(){
					$('#westu').parent().next().hide();$('#payMyOrderBtn').show();
					payment.changeTossfkh();
				});
				$('#payMentMethod3').click(function(){
					$('#westu').parent().next().hide();$('#payMyOrderBtn').show();
					payment.changeTossfkh1();
					$('#paycardinfo').load("/pay-payinfo");	
				});
				$('#payMentMethod4').click(function(){
					$('#westu').parent().next().hide();$('#payMyOrderBtn').show();
					payment.changeToyourpay();
				});
				<?php if ($this->canUseCredit):?>
				$('#payMentMethod5').click(function(){
					$('#westu').parent().next().hide();$('#payMyOrderBtn').show();
					payment.changeTocredit();
				});
				<?php endif;?>
				$('#payMentMethod3').click();
				$(document).ready(function(){
					GGSHOP.loading.hidden();
					$('#payMyOrderBtn').val('Pay My Order');
					$('#payMyOrderBtn').click(function(){
						if ($('input[name="payment_action"]').val() == 'pay-ssfkh1') {
							if (submitToPayemnt()) {
								dopay();
							}
						} else {
							dopay();
						}
					});
				});
            </script>